<template>
<a-form :form="form">
    <a-row :gutter="24">
        
        <a-col :key="1" :span="12">
            <a-form-item label="设备型号" :labelCol="{lg: {span: 8}, sm: {span: 8}}"
                          :wrapperCol="{lg: {span: 16}, sm: {span: 16} }">
                <a-input placeholder="请输入设备型号" v-decorator="[
                    'name',{rules: [{ required: true, message: '请输入设备型号' }]}]"/>
            </a-form-item>
        </a-col>
        <a-col :key="2" :span="12">
            <a-form-item label="设备类型" :labelCol="{lg: {span: 8}, sm: {span: 8}}"
                          :wrapperCol="{lg: {span: 16}, sm: {span: 16} }">
                <a-select v-decorator="['type',{rules: [{ required: true, message: '请选择设备类型' }]}]"
                          placeholder="请选择设备类型">
                    <a-select-option v-for="v in types" :key="v.id" :value="v.id">
                        {{v.name}}
                    </a-select-option>
                </a-select>
            </a-form-item>
        </a-col>
        <a-col :key="3" :span="24">
            <a-form-item label="备注" :labelCol="{lg: {span: 4}, sm: {span: 4}}"
                          :wrapperCol="{lg: {span: 20}, sm: {span: 20} }">
                <a-textarea placeholder="请输入备注" v-decorator="['remark']" :rows="4"/>
            </a-form-item>
        </a-col>
        <a-col :key="5" :span="24">
            <a-form-item label="选择图片" :labelCol="{lg: {span: 4}, sm: {span: 4}}"
                          :wrapperCol="{lg: {span: 20}, sm: {span: 20} }">
                    <upload @uploadImg="uploadImg" v-decorator="['imgurl']" />
            </a-form-item>
            
        </a-col>
        <a-col :key="4" :span="24">
            <span style="color:red">{{error}}</span>
        </a-col>
    </a-row>
</a-form>

</template>




<script>
    import upload from './upload';
    export default {
        components:{
            upload
        },
        props:['types'],
    	data(){
    		return {
                form: this.$form.createForm(this),
                labelCol:{lg: {span: 7}, sm: {span: 7}},
                wrapperCol:{lg: {span: 10}, sm: {span: 17} },
                error:'',
                url:undefined
            }
    	},
    	mounted(){
    		
		},
    	methods: {
		    onSubmit(form){
                this.form.validateFields((err, values) => {
                    if (!err) {
                        values.imgurl = this.url
                        this.http('post', 'devicemodel/create', values).then(res => {
                            if (res.id) {
                                this.$message.success(res.msg, 1);
                                this.$emit("getList")
                                this.$emit("hideCreate")
                                this.form.resetFields();
                            } else {
                                this.error = res.msg
                                setTimeout(()=>{this.error = ''},3000)
                                //this.$message.error(res.msg);
                            }
                        })
                    }
                })
            
            },
            uploadImg(e){
                this.url = e.imgurl
            }
    	}
    
    
 }
</script>

